package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.customer.CustomerDO;
import com.qk.dto.customer.CustomerDTO;
import com.qk.dto.customer.CustomerListDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author: zyx
 * @created: 2025-10-16-15:50
 * @description:
 */
@Slf4j
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @PostMapping
    public Result addCustomer(@RequestBody CustomerDTO dto) {
        log.info("新增客户,参数：{}", dto);
        customerService.add(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getCustomerInfoById(@PathVariable Integer id) {
        log.info("查询客户信息,参数：{}", id);
        return Result.success(customerService.getById(id));
    }

    @GetMapping
    public Result Page(CustomerListDTO dto) {
        PageResult<CustomerDO> result =customerService.selectPage(dto);
        log.info("分页查询结果：{}", result);
        return Result.success(result);
    }

    @PutMapping
    public Result updateCustomer(@RequestBody Customer customer) {
        customer.setUpdateTime(LocalDateTime.now());
        customerService.updateById(customer);
        log.info("更新客户信息,参数：{}", customer);
        return Result.success();
    }
}
